package com.jckl.foodathon.widget;

import java.util.ArrayList;

import com.jckl.foodathon.R;
import com.jckl.foodathon.model.DrawerListWidget;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DrawerListAdapter extends BaseAdapter{
	
	private Context context;
	private ArrayList<DrawerListWidget> drawerListWidget;
	
	public DrawerListAdapter(Context context, ArrayList<DrawerListWidget> drawerListWidget){
        this.context = context;
        this.drawerListWidget = drawerListWidget;
    }

	@Override
	public int getCount() {
		return drawerListWidget.size();
	}

	@Override
	public Object getItem(int position) {
		return drawerListWidget.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(R.layout.widget_drawerlist, null);
		}
		
		ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
		TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
		TextView txtCount = (TextView) convertView.findViewById(R.id.counter);
		
		imgIcon.setImageResource(drawerListWidget.get(position).getIcon());
		txtTitle.setText(drawerListWidget.get(position).getTitle());
		
		// displaying count
        // check whether it set visible or not
        if(drawerListWidget.get(position).isCounterVisible()){
            txtCount.setText(drawerListWidget.get(position).getCount());
        }else{
            // hide the counter view
            txtCount.setVisibility(View.GONE);
        }
        
        return convertView;
	}

}
